package com.meihua.shellapp.adapter.personalcenter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.meihua.shellapp.R;
import com.meihua.shellapp.activity.maker.CustomerDetailsActivity;
import com.meihua.shellapp.databean.CustomerDataBean;

import java.util.List;

public class MakerManageAdapter extends RecyclerView.Adapter<MakerManageAdapter.MakerManageHandler> {

    private Context mContext;
    private List<CustomerDataBean> mData;

    public MakerManageAdapter(Context context, List<CustomerDataBean> data) {
        mData = data;
        mContext = context;
    }

    @Override
    public MakerManageHandler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_makerselect, null);
        // 实例化viewholder
        MakerManageHandler viewHolder = new MakerManageHandler(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MakerManageHandler holder, final int position) {
        holder.tv_number.setText("" + (position + 1));
        holder.tv_name.setText(mData.get(position).getC_name());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent in = new Intent(mContext, CustomerDetailsActivity.class);
                in.putExtra("id", mData.get(position).getC_id());
                mContext.startActivity(in);
            }
        });
    }


    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    public void setmData(List<CustomerDataBean> mData) {
        this.mData = mData;
        notifyDataSetChanged();
    }


    public class MakerManageHandler extends RecyclerView.ViewHolder {
        TextView tv_number, tv_name;

        public MakerManageHandler(View itemView) {
            super(itemView);
            tv_number = itemView.findViewById(R.id.tv_number);
            tv_name = itemView.findViewById(R.id.tv_name);
        }
    }
}